const mysql=require("mysql")
const db = require("../routers")
const config=require("./db.config")


function connct(){
    const{host,user,password,database}=config
    return mysql.createConnection({
        host,
        user,
        password,
        database
    })
}

function querySql(sql){
    const conn=connct()
    return new Promise((resolve,reject)=>{
        try{conn.query(sql,(err,res)=>{
                if(err){
                    reject(err)
                }else{
                    resolve(res)
                }
            })
        }catch(e){
            reject(e)
        }finally{

            conn.end()
        }
    })
}
module.exports={
    querySql
}